home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-09-28 | 3.8 KB | 146 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
-
- import java.util.*;
-
- import quicktime.std.StdQTConstants;
- import quicktime.std.image.GraphicsImporter;
- import quicktime.app.*;
- import quicktime.app.players.MoviePlayer;
- import quicktime.std.image.GraphicsMode;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.*;
-
- import quicktime.*;
- import quicktime.qd.*;
- import quicktime.std.*;
- import quicktime.io.*;
- import quicktime.std.image.*;
- import quicktime.util.*;
- import quicktime.std.movies.*;
- import quicktime.std.movies.media.*;
- import quicktime.app.actions.*;
- import quicktime.app.anim.*;
- import quicktime.app.display.*;
- import quicktime.app.image.*;
- import quicktime.app.players.QTPlayer;
- import quicktime.app.actions.*;
-
- import quicktime.app.spaces.*;
- import quicktime.util.QTUtils;
-
- import java.io.*;
-
- import quicktime.std.StdQTConstants;
- import quicktime.std.image.GraphicsImporter;
- import quicktime.std.movies.*;
- import quicktime.io.*;
- import quicktime.util.*;
-
- public class JavaTextDrawer implements Compositable, Listener, Notifier {
-
- public JavaTextDrawer (Paintable renderer, Dimension size, boolean makeTransparent) {
- fSize = size;
- fRenderer = renderer;
- fMakeTransparent = makeTransparent;
- }
-
- private ImageDataSequence ids;
- private NotifyListener fListener;
- private Paintable fRenderer;
- private GraphicsMode fGraphicsMode;
- private Dimension fSize;
- private boolean fMakeTransparent;
- private Object fInterest;
-
- public void setGraphicsMode(GraphicsMode mode) {
- fGraphicsMode = mode;
- }
-
- public GraphicsMode getGraphicsMode() {
- return fGraphicsMode;
- }
-
- // need to make sure we don't get a null pointer exception at this stage
- // this is OK to return NUL BECAUSE we are a notifier
- // normally sprites expect valid description and image data
- public EncodedImage getImage() {
- return (ids != null ? ids.getImage() : null);
- }
-
- public ImageDescription getDescription() {
- return (ids != null ? ids.getDescription() : null);
- }
-
- public void removedFrom(Object interest) {
- fInterest = null;
- }
-
- public void addedTo(Object interest) {
- try {
- fInterest = interest;
-
- this.doWork();
-
- if (fListener != null)
- fListener.notifyComplete();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void doWork() {
- try {
- // if we don't have an interest registered then qid can't draw its image
- if (fInterest != null) {
- // qid is only kept as a local as we only need it to produce
- // a single frame then we throw it away
- QTImageDrawer qid = new QTImageDrawer (fRenderer, fSize, Redrawable.kSingleFrame);
- //this will capture the result of the Java drawing
- qid.addedTo (fInterest);
-
- // get the image data from the java drawing in
- // a QT format
- ids = new ImageDataSequence (qid.getDescription());
- ids.addMember (qid.getImage());
-
- if (fMakeTransparent) {
- ids = ImageUtil.makeTransparent (ids, QDColor.white);
- }
-
- if (fListener != null)
- fListener.notifyComplete();
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- // this method will be called by the Compositor when it
- // detects that a Notifier has been added to it
- public boolean addNotifyListener (NotifyListener nl) {
- //we set ourselves as the Notifier for this listener
- // if the listener doesn't like us it returns false
- // otherwise we can assume that the listener is able
- // to deal with us
- if (nl.setNotifier (this) == false)
- return false;
-
- fListener = nl;
-
- if (ids != null) {
- nl.notifyComplete();
- }
-
- return true;
- }
- }